<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Boot 邮件服务配置指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 10px 20px;
            font-size: 14px;
            color: #888;
            border-bottom: 1px solid #444;
        }
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
        }
        pre code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        .step-number {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .floating-icon {
            animation: float 3s ease-in-out infinite;
        }
        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center">
            <div class="floating-icon inline-block mb-6">
                <i class="fas fa-envelope text-6xl opacity-90"></i>
            </div>
            <h1 class="text-5xl font-bold mb-4" style="font-family: 'Noto Serif SC', serif;">
                Spring Boot 邮件服务配置指南
            </h1>
            <p class="text-xl opacity-90 max-w-3xl mx-auto">
                轻松实现邮件发送功能，让你的应用与用户保持紧密联系
            </p>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Architecture Overview -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center text-gray-800">
                <i class="fas fa-sitemap mr-3 text-purple-600"></i>实现架构概览
            </h2>
            <div class="bg-white rounded-xl shadow-lg p-8">
                <div class="mermaid">
                    graph LR
                        A[Spring Boot 应用] --> B[JavaMailSender]
                        B --> C[SMTP 服务器]
                        C --> D[目标邮箱]
                        
                        E[Email 实体类] --> A
                        F[EmailUtils 工具类] --> A
                        G[YML 配置] --> B
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                        style C fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                        style D fill:#4facfe,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
        </section>

        <!-- Step 1: Enable SMTP -->
        <section class="mb-12">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                <div class="bg-gradient-to-r from-purple-600 to-indigo-600 text-white p-6">
                    <h2 class="text-2xl font-bold flex items-center">
                        <span class="step-number text-4xl mr-4">01</span>
                        <i class="fas fa-key mr-3"></i>开启账号 SMTP 服务
                    </h2>
                </div>
                <div class="p-8">
                    <p class="text-gray-700 mb-6 text-lg">
                        首先需要在邮箱服务商处开启 SMTP 服务，并获取授权码。以下是常见邮箱的 SMTP 配置：
                    </p>
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="bg-gray-50 rounded-lg p-6 text-center">
                            <i class="fas fa-envelope text-4xl text-orange-500 mb-3"></i>
                            <h3 class="font-bold mb-2">163 邮箱</h3>
                            <p class="text-sm text-gray-600">smtp.163.com</p>
                        </div>
                        <div class="bg-gray-50 rounded-lg p-6 text-center">
                            <i class="fas fa-envelope text-4xl text-blue-500 mb-3"></i>
                            <h3 class="font-bold mb-2">QQ 邮箱</h3>
                            <p class="text-sm text-gray-600">smtp.qq.com</p>
                        </div>
                        <div class="bg-gray-50 rounded-lg p-6 text-center">
                            <i class="fas fa-envelope text-4xl text-red-500 mb-3"></i>
                            <h3 class="font-bold mb-2">Gmail</h3>
                            <p class="text-sm text-gray-600">smtp.gmail.com</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Step 2: Import Dependencies -->
        <section class="mb-12">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                <div class="bg-gradient-to-r from-indigo-600 to-purple-600 text-white p-6">
                    <h2 class="text-2xl font-bold flex items-center">
                        <span class="step-number text-4xl mr-4">02</span>
                        <i class="fas fa-cube mr-3"></i>导入依赖
                    </h2>
                </div>
                <div class="p-8">
                    <p class="text-gray-700 mb-6 text-lg">
                        在 pom.xml 中添加 Spring Boot Mail 起步依赖：
                    </p>
                    <div class="code-block">
                        <div class="code-header">
                            <i class="fas fa-code mr-2"></i>pom.xml
                        </div>
                        <pre><code class="text-gray-300">&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Step 3: YML Configuration -->
        <section class="mb-12">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                <div class="bg-gradient-to-r from-purple-600 to-pink-600 text-white p-6">
                    <h2 class="text-2xl font-bold flex items-center">
                        <span class="step-number text-4xl mr-4">03</span>
                        <i class="fas fa-cog mr-3"></i>YML 配置
                    </h2>
                </div>
                <div class="p-8">
                    <p class="text-gray-700 mb-6 text-lg">
                        在 application.yml 中配置邮件服务器信息：
                    </p>
                    <div class="code-block">
                        <div class="code-header">
                            <i class="fas fa-file-code mr-2"></i>application.yml
                        </div>
                        <pre><code class="text-gray-300">spring:
  mail:
    username: 你的邮箱账号
    password: 你的授权码  # 注意：这里是授权码，不是邮箱密码
    host: smtp.163.com</code></pre>
                    </div>
                    <div class="mt-6 bg-yellow-50 border-l-4 border-yellow-400 p-4 rounded">
                        <p class="text-yellow-800">
                            <i class="fas fa-exclamation-triangle mr-2"></i>
                            <strong>重要提示：</strong>password 字段填写的是邮箱授权码，而非登录密码！
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Step 4: Email Entity -->
        <section class="mb-12">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                <div class="bg-gradient-to-r from-pink-600 to-red-600 text-white p-6">
                    <h2 class="text-2xl font-bold flex items-center">
                        <span class="step-number text-4xl mr-4">04</span>
                        <i class="fas fa-database mr-3"></i>封装邮件实体类
                    </h2>
                </div>
                <div class="p-8">
                    <p class="text-gray-700 mb-6 text-lg">
                        创建 Email 实体类，用于封装邮件信息：
                    </p>
                    <div class="code-block">
                        <div class="code-header">
                            <i class="fas fa-file-code mr-2"></i>Email.java
                        </div>
                        <pre><code class="text-gray-300">package com.ts.blog.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Email implements Serializable {
    
    private String to;      // 收件人邮箱
    private String title;   // 邮件标题
    private String content; // 邮件内容
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Step 5: Email Utils -->
        <section class="mb-12">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                <div class="bg-gradient-to-r from-red-600 to-orange-600 text-white p-6">
                    <h2 class="text-2xl font-bold flex items-center">
                        <span class="step-number text-4xl mr-4">05</span>
                        <i class="fas fa-tools mr-3"></i>发送邮件工具类
                    </h2>
                </div>
                <div class="p-8">
                    <p class="text-gray-700 mb-6 text-lg">
                        创建 EmailUtils 工具类，封装邮件发送逻辑：
                    </p>
                    <div class="code-block">
                        <div class="code-header">
                            <i class="fas fa-file-code mr-2"></i>EmailUtils.java
                        </div>
                        <pre><code class="text-gray-300">package com.ts.blog.utils;

import com.qf.blog.entity.Email;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

@Component
public class EmailUtils {

    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String fromEmail;

    public void send(Email email) {
        // 1. 创建邮件对象
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();

        try {
            // 2. 创建邮件帮助类
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
            
            helper.setTo(email.getTo());           // 设置收件人
            helper.setSubject(email.getTitle());   // 设置标题
            helper.setText(email.getContent(), true); // 设置内容，支持HTML
            helper.setFrom(fromEmail);             // 设置发件人
            
            javaMailSender.send(mimeMessage);      // 发送邮件
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Step 6: Test -->
        <section class="mb-12">
            <div class="bg-white rounded-xl shadow-lg overflow-hidden card-hover">
                <div class="bg-gradient-to-r from-orange-600 to-yellow-600 text-white p-6">
                    <h2 class="text-2xl font-bold flex items-center">
                        <span class="step-number text-4xl mr-4">06</span>
                        <i class="fas fa-flask mr-3"></i>测试邮件发送
                    </h2>
                </div>
                <div class="p-8">
                    <p class="text-gray-